1. Field of the Invention
The present invention relates generally to the field of graphics processing and more specifically to a system and method for bump mapping setup.
2. Description of the Related Art
A typical computing system includes a central processing unit (CPU) and a graphics processing unit (GPU). Some GPUs are capable of very high performance using a relatively large number of small, parallel execution threads on dedicated programmable hardware processing units. The specialized design of such GPUs usually allows these GPUs to perform certain tasks, such as rendering 3-D scenes, much faster than a CPU. However, the specialized design of these GPUs also limits the types of tasks that the GPU can perform. The CPU is typically a more general-purpose processing unit and therefore can perform most tasks. Consequently, the CPU usually executes the overall structure of the software application and configures the GPU to perform specific tasks in the graphics pipeline (the collection of processing steps performed to transform 3-D images into 2-D images).
One task that may be performed when transforming 3-D scenes into 2-D images is bump mapping. As is well-known, bump mapping is a rendering approach for simulating lighting effects caused by surface irregularities, such as bumps, wrinkles, and divots. For example, a golf ball may have dimples, which we visually perceive because of the way that light interacts with the surface of the golf ball. Although such surface irregularities may be modeled as geometries in the graphics model of a given object, such a graphics model would be very complex and time-consuming to process and display. Furthermore, some surface irregularities may be smaller than the size of a pixel and therefore the corresponding geometry could not be accurately rendered by the GPU. To address these issues, the object may instead be modeled using simpler geometries to convey the overall shape of the object, and any surface irregularities may be captured as texture maps. Bump mapping techniques use such texture maps in conjunction with the geometries of the object to simulate the lighting effects of the surface irregularities, thereby improving the realism of the graphics image of the object.
One approach to bump mapping divides the bump mapping process into two tasks. The first task is to generate a perturbed surface normal map representing the texture of an object. In this approach, each normal in the perturbed surface normal map may be a direction vector that points up and away from the surface. Typically, the normal (0, 0, 1) represents a flat surface, and any surface variation, such as a dimple, is represented by a normal with a corresponding tilt. The perturbed surface normal map is often generated in a coordinate system called the texture-space.
The second task in the bump mapping process is to perform lighting calculations using the perturbed surface normal map to render and illuminate the object. One approach to this task performs the lighting calculations using the dot product of each of the light vectors and view vectors of each of the pixels of the geometries of the object with the perturbed surface normal map. However, to calculate the dot product, the light vectors and view vectors must share a consistent coordinate system with the normal map. The light vectors and view vectors are typically defined in another coordinate system, such as the object-space. Therefore, bump mapping programs often construct an object-space to texture-space mapping to transform the object-space light vectors and view vectors to texture-space equivalents. Once the light vectors and view vectors are defined in texture-space, the lighting calculations are performed, and the object may be rendered with the texture data.
To create realistic lighting effects, the object-space to texture-space mapping is constructed for each vertex of a given primitive. Both information specific to a graphics primitive, such as a triangle, and information specific to a particular vertex in a graphics primitive, such as the vertex encompassing the upper-left point in a triangle, may be used to create the object-space to texture-space mapping. For example, the object-space to texture-space mapping may include three normalized vectors—the per-primitive tangent vector, the per-vertex normal (the mean of the surface normals of all the primitives that share the particular vertex), and the cross-product of the tangent vector and the per-vertex normal. Furthermore, the object-space to texture-space mapping is dynamic—as the object represented in object-space animates or morphs, the object-space to texture space mapping also changes.
In one approach to bump mapping, the CPU is used to calculate the object-space to texture-space mapping. Since the object-space to texture-space mapping may be different for each primitive, the CPU constructs individual primitives consisting of vertices that are unique to each primitive. One drawback to this approach is that the CPU has to replicate each vertex shared by two or more different primitives in order to construct the individual primitives. Replicating data in such a fashion is inefficient. Furthermore, since the CPU constructs the primitives and calculates the object-space to texture-space mapping, the vertices must be available to the CPU. Therefore, in this approach, the CPU is usually used to perform the vertex processing tasks, in addition to the object-space to texture-space mapping, to avoid having to pass vertex data from the vertex shader in the GPU to the CPU. Since the CPU performs vertex processing tasks much less efficiently than the vertex shader, the capabilities of the vertex shader in this approach are oftentimes not properly leveraged. As indicated, this problem can be addressed by using the vertex shader to perform the vertex processing tasks, but such a solution would require the vertices to be passed from the vertex shader back to the CPU and, therefore, would not necessarily improve the overall efficiency of the bump mapping setup.
As the foregoing illustrates, what is needed in the art is a more effective technique for bump mapping setup.